# -*- coding: utf-8 -*-
"""
-------------------------------------------------
Project Name: luffcity study project
File Name: 进程属性练习.py
Author: kij
Create Date: 2021/3/18
-------------------------------------------------
"""
import time, os
from multiprocessing import Process


class MyProcess(Process):
	def __init__(self,name):
		super(MyProcess, self).__init__()
		self.name = "子进程-{}".format(name)
	def run(self):
		print("{} 进程id= {} 父进程id= {} ".format(self.name,os.getpid(), os.getppid()))


if __name__ == "__main__":
	process_list = []
	start = time.time()
	for item in range(10):
		my_process = MyProcess(item)
		# 守护进程在start前添加，主进程结束后子进程结束
		my_process.daemon = True
		process_list.append(my_process)
		my_process.start()
	# join方法不分先后顺序，先等join的子进程代码运行完后再去执行主进程代码
	for item in process_list:
		item.join()
	stop = time.time()
	print('主进程',os.getpid(),os.getppid())
	print(stop-start)

